﻿using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

using Magicodes.ExporterAndImporter.Excel.AspNetCore;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NP.BPMReportPlatform.DBHelper;
using NP.BPMReportPlatform.ElectronicSign;
using NP.BPMReportPlatform.Entities.BPM_Platform;
using NP.BPMReportPlatform.RecurringJobs;
using NP.BPMReportPlatform.RecurringJobs.Dto;
using NP.BPMReportPlatform.Samples.Dtos;
using SqlSugar;
using Volo.Abp;

namespace NP.BPMReportPlatform.Samples
{
    //[Authorize]
    [Route("api/sample")]
    public class SampleController : BPMReportPlatformController
    {
        private readonly ISampleAppService _sampleAppService;
        private readonly IEmployeeRecurringJob _recurringJob;
        private readonly ISFSyncJob _sFSyncJob;
        private readonly ISFSyncJD _sFSyncJD;
        private readonly IESService _esService;
        private readonly SqlSugarClient _dbPlatform;
        private readonly IContractUpdateSyncJob _contractUpdateSyncJob;
        private readonly IUserTrialSyncJob _userTrialSyncJob;
        private readonly IFrameOrderRecurringJob _frameOrder;
        private readonly ISFPerformanceSyncJob _sFPerformanceSyncJob;
        public SampleController(ISampleAppService sampleAppService,
            IEmployeeRecurringJob recurringJob, ISFSyncJob sFSyncJob,
            ISFSyncJD sFSyncJD,
            IESService esService,
            ISqlSugarAppService sqlSugarAppService,
            IContractUpdateSyncJob contractUpdateSyncJob,
            IUserTrialSyncJob userTrialSyncJob,
            IFrameOrderRecurringJob frameOrder,
            ISFPerformanceSyncJob sFPerformanceSyncJob)
        {
            _dbPlatform = sqlSugarAppService.GetPlatformInstance();
            _sampleAppService = sampleAppService;
            _recurringJob = recurringJob;
            _sFSyncJob = sFSyncJob;
            _sFSyncJD = sFSyncJD;
            _esService = esService;
            _contractUpdateSyncJob = contractUpdateSyncJob;
            _userTrialSyncJob = userTrialSyncJob;
            _frameOrder = frameOrder;
            _sFPerformanceSyncJob = sFPerformanceSyncJob;
        }

        [HttpGet]
        public async Task<SampleDto> GetAsync()
        {
            return await _sampleAppService.GetAsync();
        }

        [HttpGet]
        [Route("authorized")]
        public async Task<SampleDto> GetAuthorizedAsync()
        {
            return await _sampleAppService.GetAsync();
        }

        [HttpGet]
        [Route("getDemoPages")]
        public async Task<List<DemoDto>> GetDemoPagesAsync()
        {
            return await _sampleAppService.GetDemoPagesAsync();
        }

        [HttpPost]
        [Route("exportDemos")]
        public async Task<XlsxFileResult<DemoDto>> ExportDemosAsync()
        {
            var demos = await _sampleAppService.GetDemoPagesAsync();
            return new XlsxFileResult<DemoDto>(demos, "测试报表导出");
        }

        [HttpPost]
        [Route("SyncEmployeeAsync")]
        public async Task SyncEmployeeAsync()
        {
            await _recurringJob.SyncEmployeeAsync();
        }

        [HttpPost]
        [Route("SyncPortalEmployeeAsync")]
        public async Task SyncPortalEmployeeAsync()
        {
            await _recurringJob.SyncPortalEmployeeAsync();
        }

        [HttpGet]
        [Route("GetEmployeeApprover")]
        public List<UserFetchDto> GetCommonRoleUser(string workNumber)
        {
            return _sFSyncJob.GetCommonRoleUser(workNumber);
        }

        /// <summary>
        /// 通用接口：同步DOA审批角色相关数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("syncSF")]
        public async Task<string> SyncSFData()
        {
            return await _sFSyncJob.SyncSFData();
        }

        /// <summary>
        /// 合同测试：邮件推送
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("syncSendEmail")]
        public async Task SyncSendEmail()
        {
            await _sFSyncJob.SyncSendEmail();
        }

        /// <summary>
        /// 合同测试：合同到期关闭，开启
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("syncContractData")]
        public async Task SyncContractData()
        {
            await _contractUpdateSyncJob.SyncContractData();
        }

        /// <summary>
        /// HANA数据同步
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("syncHanaData")]
        public async Task SyncHANAData()
        {
            await _sFSyncJob.SyncHanaData();
        }

        /// <summary>
        /// JD数据同步
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("syncJDData")]
        public async Task SyncJDData()
        {
            await _sFSyncJD.SyncJDData();
        }

        /// <summary>
        /// JD同步同步职位分类、专业类、专业,function job的下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("SyncPickListOptions")]
        public async Task<string> SyncPickListOptions()
        {
            return await _sFSyncJD.SyncPickListOptions();
        }

        /// <summary>
        /// 试用期测试：发送邮件
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("SyncUserTrialSendEmail")]
        public async Task SyncUserTrialSendEmail()
        {
            await _userTrialSyncJob.SyncSendEmail();
        }

        /// <summary>
        /// 试用期测试：催办
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("SyncUserTrialFlowUrging")]
        public async Task SyncUserTrialFlowUrging()
        {
            await _userTrialSyncJob.SyncFlowUrging();
        }

        /// <summary>
        /// 试用期测试：获取催办数据总数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetFlowUrgingDataCount")]
        public async Task<string> GetFlowUrgingDataCount()
        {
            return await _userTrialSyncJob.GetFlowUrgingDataCount();
        }

        /// <summary>
        /// 框架订单，推送给SAP，手动
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("SyncFrameOrder")]
        public async Task SyncFrameOrder()
        {
            await _frameOrder.SyncFrameOrder();
        }

        /// <summary>
        /// 绩效考核同步接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("SyncSFPerformance")]
        public async Task SyncSFPerformance()
        {
            await _sFPerformanceSyncJob.SyncToDoData();
        }

        /// <summary>
        /// 更新表单数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("UpdatePerformanceFormData")]
        public async Task UpdateFormData()
        {
            await _sFPerformanceSyncJob.UpdateFormData();
        }

        /// <summary>
        /// 发送额外邮件
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("SendExtarEmail")]
        public async Task<string> SendExtarEmail()
        {
            return await _sFPerformanceSyncJob.SendExtarEmail();
        }
    }
}
